package com.witdata.controller.system;

import com.witdata.common.domain.Result;
import com.witdata.common.domain.Status;
import com.witdata.common.domain.dto.VersionDto;
import com.witdata.common.service.VersionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/system/version")
@RequiredArgsConstructor
public class VersionController {
    private final VersionService versionService;

    @GetMapping("/check")
    public Result<Boolean> check(@RequestParam("version") String version) {
        boolean check = versionService.check(version);
        return Result.ok(Status.SUCCESS, check);
    }

    @PostMapping("/upload")
    public Result<String> upload(
            @RequestParam("file") MultipartFile file,
            @RequestParam("name") String name,
            @RequestParam("content") String content
    ) {
        versionService.upload(file, name, content);
        return Result.ok(Status.UPLOADSUCCESS);
    }

    @GetMapping("/list")
    public Result<List<VersionDto>> getVersionList() {
        List<VersionDto> versionList = versionService.getVersionList();
        return Result.ok(Status.SUCCESS, versionList);
    }

    @GetMapping("/latest")
    public Result<VersionDto> getLatestVersion() {
        VersionDto latestVersion = versionService.getLatestVersion();
        return Result.ok(Status.SUCCESS, latestVersion);
    }

}
